package com.lww.feature.test.doublecolon;

import org.junit.Test;

import java.util.Arrays;

/**
 * @see <a href="http://xcodeabc.blogspot.com/2014/02/java-8-double-colon.html">http://xcodeabc.blogspot.com/2014/02/java-8-double-colon.html</a>
 * 双冒号操作符
 * User: yian
 * Date: 2017/4/26
 */
public class test {

    @Test
    public void referenceToStaticMethod() {
        Integer[] ary = new Integer[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 };
        Arrays.sort(ary, Integer::compare);
        Arrays.stream(ary).forEach(p-> System.out.println(p));
    }

    @Test
    public void referenceInstanceMethod() {
        Integer[] ary = new Integer[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 };
        MyCompare my = new MyCompare();
        Arrays.sort(ary, my::compareInt);
        Arrays.stream(ary).forEach(p-> System.out.println(p));

    }

    @Test
    public void referenceInstanceMethodArbitraryParticular() {
        Integer[] ary = new Integer[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 };

        Arrays.sort(ary, Integer::compareTo);

        System.out.println(Arrays.toString(ary));
    }

    @Test
    public void referenceConstructor() {
        //ICarFactory f = (String name, int maxSpeed) -> { return new CarBean(name, maxSpeed); };
        ICarFactory f = CarBean::new;
        CarBean c = f.getCar("GTR", 300);
        System.out.println("Car Name:" + c.getName() + " / Max Speed:" + c.getMaxSpeed());

    }

}
